package com.usian.service;

import com.usian.dao.ZhiMapper;
import com.usian.pojo.Zd;
import com.usian.pojo.Zhi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ZhiService {
    @Autowired
    private ZhiMapper zhiMapper;

    public void addZhi(Zhi zhi) {
        zhiMapper.insert(zhi);
    }

    public void deleteZhi(Integer id) {
        zhiMapper.deleteZhi(id);
    }

    public Zd findByid(Integer id) {
      return   zhiMapper.findByid(id);
    }

    public void upZhi(Zd zd) {
     Integer id= zhiMapper.findIdByZname(zd.getDname());
        Zhi z = new Zhi();
        z.setId(zd.getId());
        z.setZname(zd.getZname());
        z.setDid(id);
        zhiMapper.updateByPrimaryKey(z);
    }

    private Integer findIdByZname(String zname) {
        return zhiMapper.findIdByZname(zname);
    }

    public List<Zhi> findZhi1() {
        return zhiMapper.findZhi();
    }
}
